<?php

class fop_TableController extends Zend_Controller_Action
{
  function init() {
  	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function createAction() {
    require_once('fop/objects/table.php');
    try{
	  $results = fop_Object_Table::create($this->_getAllParams());
    } catch(fop_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
 	  echo serialize($data);
      return;
    }
	$data['status'] = 	'OK';
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;
  }
  
  function listAction() {
    require_once('fop/objects/table.php');
    $results = fop_Object_Table::listing();
    $data['tables'] = $results;
    
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
  }
  
  function readAction() {
    require_once('fop/objects/table.php');
    try {
      $table = new fop_Object_Table($this->_getParam('name'));
      $resTable = $table->asArray();
    } catch(fop_Object_Exception $e) {
      $data['status'] = 	'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;
    }
    
    //We list the different controllers of the table
    require_once('fop/objects/fopline.php');
    $resFoplines = fop_Object_Fopline::listing($table->getName());
    
    
	$data['status'] = 	'OK';
	$data['table'] = $resTable;
	$data['foplines'] = $resFoplines;
    echo Zend_Registry::get('dt_serializer')->serialize($data);	
    return;  	
  }

} //End class


?>